package com.macro.mall.tiny.modules.oms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.common.api.CommonPage;
import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.oms.model.OmsPromoCodeRebateLog;
import com.macro.mall.tiny.modules.oms.model.dto.OmsPromoCodeRebateLogQueryDTO;
import com.macro.mall.tiny.modules.oms.service.OmsPromoCodeRebateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import javax.swing.text.StyledEditorKit;

/**
 * <p>
 * 促销码返点变更日志 前端控制器
 * </p>
 *
 * @author tyrone
 * @since 2024-11-25
 */
@RestController
@RequestMapping("/oms/omsPromoCodeRebateLog")
@Api(tags = "OmsPromoCodeRebateLogController")
@Tag(name = "OmsPromoCodeRebateLogController", description = "优惠码返点变更日志")
public class OmsPromoCodeRebateLogController {

    @Autowired
    private OmsPromoCodeRebateLogService omsPromoCodeRebateLogService;

    @ApiOperation("后台万能分页获取变更日志")
    @PostMapping("/page")
    public CommonResult<IPage<OmsPromoCodeRebateLog>> page(@RequestBody OmsPromoCodeRebateLogQueryDTO dto) {

        QueryWrapper<OmsPromoCodeRebateLog> query = new QueryWrapper<>();
        if (dto.getPromoCode() != null) {
            query.eq("promo_code", dto.getPromoCode());
        }
        if (dto.getOpenId() != null) {
            query.eq("open_id", dto.getOpenId());
        }
        if (dto.getCreateTimeStart() != null) {
            query.ge("create_time", dto.getCreateTimeStart());
        }
        if (dto.getCreateTimeEnd() != null) {
            query.le("create_time", dto.getCreateTimeEnd());
        }
        query.orderByDesc("create_time");

        return CommonResult.success(omsPromoCodeRebateLogService.page(new Page<>(dto.getPageNum(), dto.getPageSize(), Boolean.TRUE),query));
    }

}

